#pragma once

#include "Misc/EngineEditorMacros.h"
#include "Object/Object.h"
#include "Misc/EngineEditorMacros.h"
#include "Math/Color.h"
#include "Math/IntPoint.h"
#include "WindowEnums.h"
#include "EditorWindowViewModel.m.h"

class REditorWindowModel;
class RTexture2D;
class RWindow;
class REditorPageAreaManagerViewModel;

//view model of a window
RCLASS(ExtraHeader=["PageArea/EditorPageAreaManagerViewModel.h"])
class ENGINEEDITOR_API REditorWindowViewModel : public RObject
{
    ROBJECT

public:
    virtual void BindModel(TSharedObjectPtr<REditorWindowModel> InModel);

    TSharedObjectPtr<REditorWindowModel> GetModel();
protected:
    TWeakObjectPtr<REditorWindowModel> BaseModel;

public:

    //当窗口获得焦点时调用
    void OnGotUserFocus();

    const SColor SpliterColor=SColor::FromHexRGB(0x2B2B2B);
    const float SpliterSize = 1;


    CString GetWindowTitle() const;
    void SetWindowTitle(const CString& InTitle);
    TDelegate<void> OnWindowTitleChanged;


    EWindowSizeType GetWindowSizeType() const;
    void SetWindowSizeType(EWindowSizeType InType);
    TDelegate<void> OnWindowSizeTypeChanged;

    //only effected when SizeType is Normal
    SIntPoint GetWindowSize() const;
    void SetWindowSize(const SIntPoint& InSize);
    TDelegate<void> OnWindowSizeChanged;

    //only effected when SizeType is Normal
    SIntPoint GetWindowPosition(TSharedObjectPtr<RWindow> InWindow) const;
    void SetWindowPosition(const SIntPoint& InPosition);
    TDelegate<void> OnWindowPositionChanged;

    const float TitleBarHeight = 36;
    const float StatusBarHeight = 23; 
    
    //temp variable for drag window
    bool bIsDraggingWindow = false;
    SIntPoint WindowPositionOnDragStarted;
    SIntPoint MousePositionOnDragStarted;

    bool IsResizable() const;
    const float ResizeBorderSize = 4;
    //temp variable for resize window
    bool bIsResizingWindow = false;
    SIntPoint WindowSizeOnResizeStarted;
    SIntPoint WindowPositionOnResizeStarted;
    SIntPoint MousePositionOnResizeStarted;//screen position

    //window buttons
    const float WindowButtonWidth = 34;
    const float WindowButtonImageSize = 15;
    const SColor WindowsButtonBackgroundColor=SColor::FromHexRGB(0x373737);
    const SColor WindowsCloseBackgroundColor=SColor::FromHexRGB(0xE81123);
    
    TSharedObjectPtr<RTexture2D> GetMinimizeButtonImage() const;
    //when window is maximized, this image will be restore button image
    TSharedObjectPtr<RTexture2D> GetMaximizeButtonImage() const;
    TSharedObjectPtr<RTexture2D> GetCloseButtonImage() const;

    const float WindowLeftTopIconSize = 32;
    const float WindowLeftTopIconLeftMargin = 3;
    TSharedObjectPtr<RTexture2D> GetWindowLeftTopIcon() const;

protected:
    CString WindowTitle = U"Editor";
    
    TSharedObjectPtr<RTexture2D>  MinimizeButtonImage;
    TSharedObjectPtr<RTexture2D>  MaximizeButtonImage;
    TSharedObjectPtr<RTexture2D>  RestoreButtonImage;
    TSharedObjectPtr<RTexture2D>  CloseButtonImage;
    TSharedObjectPtr<RTexture2D> EngineIcon;

//页面相关
public:
    //editor area
    TSharedObjectPtr<REditorPageAreaManagerViewModel> GetPageArea() const;

protected:
    RFIELD()
    TSharedObjectPtr<REditorPageAreaManagerViewModel> PageAreaViewModel;

};